#include "myScreen.h"

MyScreen::MyScreen()
{
}

MyScreen::~MyScreen()
{
}

void MyScreen::Render()
{
	this->pEngine->GetGraphics()->DrawCamera(this->pMyCamera);

	this->pEngine->GetGraphics()->EnableDepthTesting();

	this->pEngine->GetGraphics()->DrawEntity(this->pMyEntity);

	this->pEngine->GetGraphics()->DisableDepthTesting();

	this->pEngine->GetGraphics()->Setup2DProjection();
}

void MyScreen::Update(float fDelta)
{
	this->pMyEntity->UpdateAnimation(fDelta);
}

void MyScreen::Load()
{
	this->pMyCamera = new Camera(0, 0, this->ScreenWidth(), this->ScreenHeight());
	this->pMyCamera->SetPerspectiveProjection(60.0f, 1.33f, 0.1f, 300.0f);
	this->pMyCamera->SetBackgroundColor(Color(255, 189, 38));
	this->pMyCamera->Move(0, 0, 70);

	this->pMyTexture = this->pEngine->GetGraphics()->LoadTexture("media/homer.bmp");

	this->pMyEntity = MD2EntityLoader::LoadFromFile("media/homer.md2");
	this->pMyEntity->GetModel(0)->SetTexture(this->pMyTexture);

	this->pMyEntity->AddAnimation("stand", 0, 39, 8);
	this->pMyEntity->PlayAnimation("stand", DelGEGraphics_Animation_Playstyle_Loop);
}

void MyScreen::Unload()
{
	this->pMyEntity->Destroy();

	delete this->pMyCamera;
	delete this->pMyEntity;
	delete this->pMyTexture;
}